package action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import entitybean.l_sequence.EntityBeanL_Sequence;
import entitybean.oc_property.EntityBean_Oc_Property;
import entitybean.oc_property_ben.EntityBean_Oc_Property_Ben;
import form.PropertyBenForm;
import form.PropertyForm;

import service.service_admin.Service_Admin;
import service.service_public.Service_Public;
import tools.InterfaceForResultSetToList;
import tools.PageBeanPlus;
import view.ViewOc_Property;
import view.ViewOc_Property_Ben;

public class Action_Oc_Property_Ben extends DispatchAction {
	private Service_Admin service_admin;
	private Service_Public service_public;
	public Service_Admin getService_admin() {
		return service_admin;
	}

	public void setService_admin(Service_Admin serviceAdmin) {
		service_admin = serviceAdmin;
	}

	public Service_Public getService_public() {
		return service_public;
	}

	public void setService_public(Service_Public servicePublic) {
		service_public = servicePublic;
	}

	public ActionForward admin_init_oc_property_ben(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		PropertyBenForm propertybenform = (PropertyBenForm) form;

		System.out.println("初始化海洋环境科考船");
		String sql = "select ID,PROPERTY_NAME from OC_PROPERTY_BEN where DEL='OFF' AND KIND_ID=8";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(propertybenform.getRowcountperpage()), Integer
						.valueOf(propertybenform.getCurrentpage()),
				"loadrichtext()");
		InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
		List<ViewOc_Property_Ben> list = interfaceforresultsettolist
				.ViewOc_Property_Ben(pagebeanplus.getFormatqueryresultset());
		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("propertybenform", propertybenform);
		System.out.println("list.size()" + list.size());
		
		
		return mapping.findForward("success");
		
	}

	public ActionForward admin_load_oc_property_ben(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		PropertyBenForm propertybenform = (PropertyBenForm) form;
		String id=propertybenform.getId();
		EntityBean_Oc_Property_Ben e=this.service_admin.Find_EntityBean_Oc_Property_Ben_By_Id(id);
		request.setAttribute("e", e);
		return mapping.findForward("success");
	}

	public ActionForward admin_add_oc_property_ben(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		return mapping.findForward("success");
	}

	public ActionForward admin_insert_oc_property_ben(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		
		PropertyBenForm propertybenform = (PropertyBenForm) form;

		String propertyName = propertybenform.getProperty_name();
		EntityBean_Oc_Property_Ben e = new EntityBean_Oc_Property_Ben();
		EntityBeanL_Sequence l = this.service_public
				.Find_L_Sequence_By_seq_Name("SEQ_OC_PROPERTY_BEN");
		Integer id = l.getSeq_Value() + 1;
		l.setSeq_Value(id);
		e.setId(id);
		e.setDel("OFF");
		e.setProperty_name(propertyName);
		e.setKind_id(8);
		this.service_admin.Insert_Oc_Property_Ben(e);
		this.service_public.Update_L_Sequence(l);
		
		
		System.out.println("初始化海洋环境科考船");
		String sql = "select ID,PROPERTY_NAME from OC_PROPERTY_BEN where DEL='OFF' AND KIND_ID=8";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(propertybenform.getRowcountperpage()), Integer
						.valueOf(propertybenform.getCurrentpage()),
				"loadrichtext()");
		InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
		List<ViewOc_Property_Ben> list = interfaceforresultsettolist
				.ViewOc_Property_Ben(pagebeanplus.getFormatqueryresultset());
		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("propertybenform", propertybenform);
		System.out.println("list.size()" + list.size());
		
		
		return mapping.findForward("success");
	}

	public ActionForward admin_delete_oc_property_ben(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		PropertyBenForm propertybenform = (PropertyBenForm) form;
		String id=propertybenform.getId();
		id=this.cut_tail(id);
		this.service_admin.Delete_Oc_Property_Ben(id);
		System.out.println("初始化海洋环境科考船");
		String sql = "select ID,PROPERTY_NAME from OC_PROPERTY_BEN where DEL='OFF' AND KIND_ID=8";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(propertybenform.getRowcountperpage()), Integer
						.valueOf(propertybenform.getCurrentpage()),
				"loadrichtext()");
		InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
		List<ViewOc_Property_Ben> list = interfaceforresultsettolist
				.ViewOc_Property_Ben(pagebeanplus.getFormatqueryresultset());
		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("propertybenform", propertybenform);
		System.out.println("list.size()" + list.size());
		return mapping.findForward("success");
	}

	public ActionForward admin_update_oc_property_ben(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		PropertyBenForm propertybenform = (PropertyBenForm) form;
		String id=propertybenform.getId();
		String propertyName = propertybenform.getProperty_name();
		EntityBean_Oc_Property_Ben e = new EntityBean_Oc_Property_Ben();
		e=this.service_admin.Find_EntityBean_Oc_Property_Ben_By_Id(id);
		e.setProperty_name(propertyName);
		this.service_admin.Update_Oc_Property_Ben(e);
		
		System.out.println("初始化海洋环境科考船");
		String sql = "select ID,PROPERTY_NAME from OC_PROPERTY_BEN where DEL='OFF' AND KIND_ID=8";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(propertybenform.getRowcountperpage()), Integer
						.valueOf(propertybenform.getCurrentpage()),
				"loadrichtext()");
		InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
		List<ViewOc_Property_Ben> list = interfaceforresultsettolist
				.ViewOc_Property_Ben(pagebeanplus.getFormatqueryresultset());
		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("propertybenform", propertybenform);
		System.out.println("list.size()" + list.size());
		
		
		
		return mapping.findForward("success");
	}

	public ActionForward admin_search_oc_property_ben(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		PropertyBenForm propertybenform = (PropertyBenForm) form;

		System.out.println("初始化海洋环境科考船");
		String sql = "select ID,PROPERTY_NAME from OC_PROPERTY_BEN where DEL='OFF' AND KIND_ID=8";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(propertybenform.getRowcountperpage()), Integer
						.valueOf(propertybenform.getCurrentpage()),
				"loadrichtext()");
		InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
		List<ViewOc_Property_Ben> list = interfaceforresultsettolist
				.ViewOc_Property_Ben(pagebeanplus.getFormatqueryresultset());
		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("propertybenform", propertybenform);
		System.out.println("list.size()" + list.size());
		
		
		return mapping.findForward("success");
	}

	private String cut_tail(String str) {
		String cut = str;
		if (str.endsWith(",")) {
			cut = cut.substring(0, cut.length() - 1);
		}
		return cut;
	}
}
